package com.red.wine.sql;

import java.util.ArrayList;
import java.util.List;

import com.red.wine.R;
import com.red.wine.WineApp;
import com.red.wine.util.StringUtil;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;

/**
 * TODO 数据库基类
 */
public class SqlHelper extends SQLiteOpenHelper {

	private static int DB_VERSION = 180;

	/**
	 * @return 返回SQL版本
	 */
	public static int getDBVersion() {
		return DB_VERSION;
	}

	public SqlHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(WineApp.getInstance().getString(R.string.city_data_list));
		db.execSQL(WineApp.getInstance().getString(R.string.myfover));
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion < newVersion) {
			String sql = "DROP TABLE IF EXISTS {0};";
			db.execSQL(StringUtil.format(sql, "city_dataa_list"));
			db.execSQL(StringUtil.format(sql, "myfour"));
			onCreate(db);
		} else {
			onCreate(db);
		}
	}

}
